import scrapy
import re


class Login3Spider(scrapy.Spider):
    name = 'gitLogin3'
    allowed_domains = ['github.com']
    start_urls = ['https://github.com/login']

    def parse(self, response):
        yield scrapy.FormRequest.from_response(
            response,  # 传入response对象,自动解析
            # 可以通过xpath来定位form表单,当前页只有一个form表单时,将会自动定位
            formxpath='//*[@id="js-pjax-container"]/form',
            formdata={'login': '940013154@qq.com', 'password': 'xiaomao321'},
            callback=self.parse_login
        )

    def parse_login(self, response):
        ret = re.findall(r"noobpythoner|NoobPythoner", response.text)
